<template>
	<view>
		<view class="top_img">
			<image mode="widthFix" src="/static/pages/image/store_bg.png"></image>
		</view>
		<view class="cont_box">
			<view class="cont_tit">
				<label class="line_le">卖车流程</label>
			</view>
			<view class="cont_word">
				<view class="c_word">注册会员</view>
				<view class="c_img">
					<image mode="aspectFill" src="/static/pages/image/jiantou_btn.png"></image>
				</view>
				<view class="c_word">提交信息</view>
				<view class="c_img">
					<image mode="aspectFill" src="/static/pages/image/jiantou_btn.png"></image>
				</view>
				<view class="c_word">等待询价</view>
				<view class="c_img">
					<image mode="aspectFill" src="/static/pages/image/jiantou_btn.png"></image>
				</view>
				<view class="c_word">交易完成</view>
			</view>
		</view>
		<view class="cont_box">
			<view class="cont_tit">
				<label class="line_le">卖车保障</label>
			</view>
			<view class="cont_lab_box">
				<view class="lab_box">
					<label>极速匹配</label>
				</view>
				<view class="lab_box">
					<label>一站服务</label>
				</view>
				<view class="lab_box">
					<label>价格透明</label>
				</view>
			</view>
			<view class="t_img">
				<image mode="aspectFill" src="/static/pages/image/tishi.png"></image>
			</view>
			<view class="tishi">温馨提示</view>
			<view class="tishi_text">想尽快售出，不要标价太高哦！</view>
		</view>
		<block v-if="now_status==0">
			<view class="send_box">
				<button class="sale_butt" @tap="click_toSale">我要卖车</button>
				<picker class="pic_box" @change="bindPickerChange" :value="index" :range="classArr">
					<view class="picker">
						当前选择：{{classArr[index]}}
					</view>
				</picker>
			</view>
		</block>
		<new-order />
	</view>
</template>

<script>
	var app = getApp();

	export default {
		data() {
			return {
				array: ['发布卖车信息', '发布卖配件信息'],
				index: '',
				classArr: [],
				allArr: [],
				now_status: 1
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			var that = this;
			that.getClass();
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			var that = this;
			that.check_status();
		},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			check_status: function() {
				var that = this;
				app.globalData.util.request({
					url: "entry/wxapp/Api",
					data: {
						m: "monai_market",
						r: "home.index.examine"
					},
					success: function(res) {
						console.log('状态', res.data); // 1 开 0 关

						that.setData({
							now_status: res.data.data
						});
					},
					fail: function(res) {}
				});
			},
			//获取分类信息
			getClass: function() {
				var that = this;
				app.globalData.util.request({
					url: "entry/wxapp/Api",
					data: {
						m: "monai_market",
						uid: app.globalData.getuid(),
						r: "sale.index.saleindex"
					},
					cachetime: "0",
					success: function(res) {
						console.log('发布分类：', res.data);
						var all = res.data.data.class;
						var array = [];
						var larr = [{
							id: '-1',
							uniacid: '',
							name: '配件库',
							brand_icon: '',
							sort: ''
						}];

						for (var i = 0; i < all.length; i++) {
							array.push(all[i].name);
						}

						all = all.concat(larr); //array.push('配件库');

						console.log(array);
						console.log(all);
						that.setData({
							classArr: array,
							allArr: all
						});
					}
				});
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value);
				var that = this;
				var id = e.detail.value;
				this.setData({
					index: id
				});
				var t = this;
				app.globalData.util.request({
					url: "entry/wxapp/Api",
					data: {
						m: "monai_market",
						r: "home.index.vipinfo",
						uid: app.globalData.getuid()
					},
					cachetime: "0",
					success: function(a) {
						console.log('会员信息返回：', a.data);
						var json = a.data.data; // if (json.is_buyvip == 0) {

						var cid = that.allArr[id].id,
							name = that.allArr[id].name;

						if (cid != '-1') {
							console.log('卖车');

							if (json.vip_limitimes * 1 < 0) {
								wx.navigateTo({
									url: '../sale/index?cid=' + cid + '&name=' + name
								});
							} else {
								if (json.fb_infotimes * 1 < json.vip_limitimes * 1) {
									wx.navigateTo({
										url: '../sale/index?cid=' + cid + '&name=' + name
									});
								} else {
									wx.showModal({
										title: '温馨提示',
										content: '超过免费发布信息，支付5元继续发布',
										showCancel: false,
										success: function(res) {
											if (res.confirm) {
												//点击确定
												// wx.navigateTo({
												//   url: '../member/member',
												// })
												app.globalData.util.request({
													url: "entry/wxapp/Relpay",
													data: {
														m: "monai_market",
														// r: "me.follow",
														uid: app.globalData.getuid(),
														price: 5
													},
													cachetime: "0",
													success: function(a) {
														wx.requestPayment({
															timeStamp: a
																.data.data
																.timeStamp,
															nonceStr: a
																.data.data
																.nonceStr,
															package: a.data
																.data
																.package,
															signType: a
																.data.data
																.signType,
															paySign: a.data
																.data
																.paySign,

															success(
															result) {
																// wx.showToast({
																//     title: '支付成功',
																//     icon: 'success',
																//     duration: 2000,
																// })
																wx.navigateTo({
																	url: '../sale/index?cid=' +
																		cid +
																		'&name=' +
																		name
																});
															},

															fail(err) {
																wx.showToast({
																	title: '支付失败',
																	icon: 'none',
																	duration: 2000
																});
															}

														});
													}
												});
											} else { //点击取消
											}
										}
									});
								}
							}
						} else {
							console.log('卖配件');
							wx.navigateTo({
								url: '/pagesA/parts/parts?tid=1'
							});
						} // } else {
						//   var cid = that.data.allArr[id].id,
						//     name = that.data.allArr[id].name;
						//   if (cid != '-1') {
						//     console.log('卖车');
						//     if (json.vip_level != 2 && json.fb_infotimes * 1 >= 50) {
						//       wx.showModal({
						//         title: '温馨提示',
						//         content: '开通成为高级会员，无限上传图片',
						//         showCancel: false,
						//         success: function (res) {
						//           if (res.confirm) {
						//             //点击确定
						//             wx.navigateTo({
						//               url: '../member/member',
						//             })
						//           } else {
						//             //点击取消
						//           }
						//         }
						//       })
						//     } else {
						//       wx.navigateTo({
						//         url: '../sale/index?cid=' + cid + '&name=' + name,
						//       })
						//     }
						//   } else {
						//     console.log('卖配件');
						//     wx.navigateTo({
						//       url: '../parts/parts?tid=1',
						//     })
						//   }
						// }

					}
				});
			},
			//点击我要卖车按钮跳转页面、
			click_toSale: function() {}
		}
	};
</script>
<style>
	@import "./carSale.css";
</style>
